package q784_letterCasePermutation;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    List<String> res = new ArrayList<>();

    public List<String> letterCasePermutation(String s) {
        if (s.length() == 0) {
            return res;
        }
        char[] chars = s.toCharArray();
        dfs(0, chars);
        return res;
    }

    private void dfs(int index, char[] chars) {
        // 此题类似于子集问题 全部的种类都需要加入
        res.add(new String(chars));

        for (int i = index; i < chars.length; i++) {
            if (Character.isLetter(chars[i])) {
                // 操作逻辑
                char temp = chars[i];
                chars[i] = (char)(chars[i] - 'a' >= 0 ? chars[i] - 32 : chars[i] + 32);;
                // dfs
                dfs(i + 1, chars);
                // 消除操作逻辑
                chars[i] = temp;
            }
        }
    }
}
